﻿using System;
using System.Runtime.InteropServices;

namespace YJKRevitDimensionText.AnnotationSetting
{
	public class AnalogClicks
	{
		[DllImport("user32.dll")]
		private static extern void mouse_event(AnalogClicks.MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);

		[DllImport("user32.dll")]
		public static extern int SetCursorPos(int x, int y);

		public static void MouseMiddleClickEvent(int dx, int dy, uint data)
		{
			AnalogClicks.SetCursorPos(dx, dy);
			AnalogClicks.mouse_event(AnalogClicks.MouseEventFlag.MiddleDown, dx, dy, data, UIntPtr.Zero);
			AnalogClicks.mouse_event(AnalogClicks.MouseEventFlag.MiddleUp, dx, dy, data, UIntPtr.Zero);
		}

		private enum MouseEventFlag : uint
		{
			Move = 1u,
			LeftDown,
			LeftUp = 4u,
			RightDown = 8u,
			RightUp = 16u,
			MiddleDown = 32u,
			MiddleUp = 64u,
			XDown = 128u,
			XUp = 256u,
			Wheel = 2048u,
			VirtualDesk = 16384u,
			Absolute = 32768u
		}
	}
}
